package com.zingrow.web.configure.weixin.controller;

import java.io.File;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.support.DefaultMultipartHttpServletRequest;

import com.idaycrm.idaybase.utils.JsonUtils;
import com.zingrow.common.ReturnStandardDataFormat;
import com.zingrow.common.utils.CommonUtils;
import com.zingrow.common.utils.EncodingUtils;
import com.zingrow.common.utils.ExcelUtils;
import com.zingrow.common.utils.OptClass;
import com.zingrow.common.utils.PageView;
import com.zingrow.web.base.CodeMsg;
import com.zingrow.web.base.controller.BaseController;
import com.zingrow.web.base.enums.Menu;
import com.zingrow.web.base.enums.Operation;
import com.zingrow.web.common.utils.AnalyzeResult;
import com.zingrow.web.configure.iformation.model.Iformation;
import com.zingrow.web.configure.iformation.service.IIformationService;
import com.zingrow.web.configure.weixin.model.Weixin;
import com.zingrow.web.configure.weixin.service.IWeixinService;
import com.zingrow.web.support.operate.model.OptRecord;
import com.zingrow.web.support.operate.service.IOptRecordService;
import com.zingrow.web.user.model.ActiveUser;
import com.zingrow.web.user.model.UserPermission;
import com.zingrow.web.user.service.IPermissionService;

@Controller
@RequestMapping(value="/weixin/",produces="application/json;charset=UTF-8")
public class WeixinController extends BaseController {
	@Autowired
	private IWeixinService weixinService;
	@Autowired
	private IOptRecordService optRecordService;
	@Autowired
	private IIformationService iformationService;
	@Autowired
	private IPermissionService permissionService;
	@Autowired
	private IOptRecordService ioptRecordService;
	
	
	//模糊查询
	@ResponseBody
	@RequestMapping("queryParams")
	public String queryByParams(HttpServletRequest request,HttpServletResponse response,
			Integer pageIndex,Integer pageSize,String weixinuser_Id,String weixin_name,Integer is_exprot,String sp){
		List<Weixin> list = new ArrayList<>();
		ReturnStandardDataFormat StandardData = new ReturnStandardDataFormat(CodeMsg.CODE_ERROR,CodeMsg.MSG_ERROR,list);
		PageView pageView = null;
		try {
			//给分页参数赋初始值
			if(pageIndex == null || pageIndex <= 0){
				pageIndex = 1;
			}
			if(pageSize == null || pageSize <= 0){
				pageSize = 10;
			}
			pageView = new PageView(pageSize,pageIndex);
			//字符转换
			if(weixinuser_Id != null || "".equals(weixinuser_Id)){
				weixinuser_Id = EncodingUtils.fixUrlParamEncoding(request, weixinuser_Id);
			}
			if(weixin_name != null || "".equals(weixin_name)){
				weixin_name = EncodingUtils.fixUrlParamEncoding(request, weixin_name);
			}
			list = weixinService.queryByParams(pageView, weixinuser_Id, weixin_name,is_exprot);
			if("weixin".equals(sp))
			{
				//新增一条操作记录
				ActiveUser opuser = getUser(request);//获取操作用户
				OptRecord s = new OptClass().weixin_query(opuser,Menu.Resourceallocation.toString(),
						Menu.weixin.toString(),Operation.query.toString(),weixinuser_Id,weixin_name);
				if(!s.getOptName().equals("null"))	
				ioptRecordService.insert(s);
			}
		} catch (Exception e) {
			log.error("根据参数查询异常");
			ActiveUser opuser = getUser(request);//获取操作用户
			OptRecord s = new OptClass().recordabnormality(opuser,"微信配置根据参数查询异常");
			ioptRecordService.insert(s);
			StandardData.setReturnCode(CodeMsg.CODE_EXCEPTION);
			StandardData.setReturnMessage(CodeMsg.MSG_EXCEPTION);
			StandardData.setReturnData(list);
		}
			StandardData.setReturnData(list);
			StandardData.setReturnCode(CodeMsg.CODE_OK);
			StandardData.setReturnMessage(CodeMsg.MSG_OK);
			StandardData.setTotalPages(pageView.getPageCount());
			StandardData.setTotalRecords(pageView.getRowCount());
			return JsonUtils.toString(StandardData, "yyyy-MM-dd HH:mm:ss");
	}
	//批量删除
	@ResponseBody
	@RequestMapping("batchDeletes")
	public String batchDeletes(HttpServletRequest request,HttpServletResponse response){	
		ReturnStandardDataFormat standardData = new ReturnStandardDataFormat(CodeMsg.CODE_ERROR,CodeMsg.MSG_ERROR,null);
       //截获请求的参数，获得要删除的微信ID
		String items = request.getParameter("weixin_id");        
        List<String> delList = new ArrayList<String>();
       //用“，”将参数分割存入数组
        String[] strs = items.split(",");
        //遍历数组将所有要删除的微信ID存入delList集合
        for (String str : strs) {
            delList.add(str);             
        }
        if (weixinService.batchDeletes(delList)) {		
			//操作成功
        	ActiveUser opuser = getUser(request);//获取操作用户
			OptRecord s = new OptClass().goiss(opuser,Menu.Resourceallocation.toString(),
					Menu.weixin.toString(),Operation.deldetes.toString(),delList.size());
			ioptRecordService.insert(s);	
			standardData.setReturnCode(CodeMsg.CODE_OK);
			standardData.setReturnMessage(CodeMsg.MSG_OK);
        }
        return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
        
    }
	//删除
	@ResponseBody
	@RequestMapping("deleteWeixin")
	public String deleteWeixin(HttpServletRequest request,HttpServletResponse response,Integer weixin_id,String weixinuser_id,String weixinuser_name){
		ReturnStandardDataFormat StandardData = new ReturnStandardDataFormat(CodeMsg.CODE_ERROR,CodeMsg.MSG_ERROR,null);
		try {
			//判断参数的合法
			if(CommonUtils.isObjectNull(weixin_id)){
				StandardData.setReturnCode(CodeMsg.CODE_ERROR_PARAMS);
				StandardData.setReturnMessage(CodeMsg.MSG_ERROR_PARAMS);
				JsonUtils.toString(StandardData, "yyyy-MM-dd HH:mm:ss");
			}
			//字符转换
			if(CommonUtils.isStrNotNull(weixinuser_id)){
				weixinuser_id = EncodingUtils.fixUrlParamEncoding(request, weixinuser_id);
			}
			if(weixinService.deleteWeixin(weixin_id)){
				//操作记录
				ActiveUser opuser = getUser(request);//获取操作用户
				OptRecord s = new OptClass().weixin_delete(opuser,Menu.Resourceallocation.toString(),
						Menu.weixin.toString(),Operation.delete.toString(),weixinuser_name);
				ioptRecordService.insert(s);	
				StandardData.setReturnCode(CodeMsg.CODE_OK);
				StandardData.setReturnMessage(CodeMsg.MSG_OK);
			}else{
				StandardData.setReturnCode(CodeMsg.CODE_ERROR);
				StandardData.setReturnMessage(CodeMsg.MSG_ERROR);
			}
		} catch (Exception e) {
			log.error("删除微信号异常");
			ActiveUser opuser = getUser(request);//获取操作用户
			OptRecord s = new OptClass().recordabnormality(opuser,"微信配置删除异常");
			ioptRecordService.insert(s);
			StandardData.setReturnCode(CodeMsg.CODE_EXCEPTION);
			StandardData.setReturnMessage(CodeMsg.MSG_EXCEPTION);
		}
		return JsonUtils.toString(StandardData, "yyyy-MM-dd HH:mm:ss");
	}
	//新增
	@ResponseBody
	@RequestMapping("addWeixin")
	public String addWeixin(HttpServletRequest request,HttpServletResponse response,Weixin weixin){
		ReturnStandardDataFormat standardData = new ReturnStandardDataFormat(CodeMsg.CODE_ERROR,CodeMsg.MSG_ERROR,null);
		try {
			//判断参数是否正常
			if(CommonUtils.isStrNull(weixin.getWeixinuser_Id())||CommonUtils.isStrNull(weixin.getWeixin_name())){
				standardData.setReturnCode(CodeMsg.CODE_ERROR_PARAMS);
				standardData.setReturnMessage(CodeMsg.MSG_ERROR_PARAMS);
				return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
			}else{
				//转码
				weixin.setWeixinuser_Id(EncodingUtils.fixUrlParamEncoding(request, weixin.getWeixinuser_Id()));
				weixin.setWeixin_name(EncodingUtils.fixUrlParamEncoding(request, weixin.getWeixin_name()));
			}
			//判断新增微信id是否相同
			if(weixinService.queryById(null, weixin.getWeixinuser_Id())){
				standardData.setReturnCode(CodeMsg.CODE_ERROR_OTHER);
				standardData.setReturnMessage("该微信号已存在，请重新输入");
				return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
			}
			//调用新增
			if(weixinService.addWeixin(weixin)){
				//操作记录
				ActiveUser opuser = getUser(request);//获取操作用户
				OptRecord s = new OptClass().weixin_add(opuser,Menu.Resourceallocation.toString(),
						Menu.weixin.toString(),Operation.insert.toString(),weixin);
				ioptRecordService.insert(s);	
				standardData.setReturnCode(CodeMsg.CODE_OK);
				standardData.setReturnMessage(CodeMsg.MSG_OK);
			}else{
				standardData.setReturnCode(CodeMsg.CODE_ERROR);
				standardData.setReturnMessage(CodeMsg.MSG_ERROR);
			}
		} catch (Exception e) {
			e.printStackTrace();
			ActiveUser opuser = getUser(request);//获取操作用户
			OptRecord s = new OptClass().recordabnormality(opuser,"微信配置新增异常");
			ioptRecordService.insert(s);
			log.error(e.getMessage());
			standardData.setReturnCode(CodeMsg.CODE_EXCEPTION);
			standardData.setReturnMessage(CodeMsg.MSG_EXCEPTION);
		}
		return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
	}
	//单个查询
	@ResponseBody
	@RequestMapping("queryWeixinById")
	public String queryWeixinById(HttpServletRequest request,HttpServletResponse response,Integer weixin_id){
		Weixin weixin = new Weixin();
		ReturnStandardDataFormat standardData = new ReturnStandardDataFormat(CodeMsg.CODE_ERROR,CodeMsg.MSG_ERROR,null);
		try {
			//判断参数是否合法
			if(CommonUtils.isObjectNull(weixin_id)){
				standardData.setReturnCode(CodeMsg.CODE_ERROR_PARAMS);
				standardData.setReturnMessage(CodeMsg.MSG_ERROR_PARAMS);
				return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
			}
			weixin = weixinService.queryWeixinById(weixin_id);
		} catch (Exception e) {
			log.error("根据参数编号查询异常");
			log.error(e.getMessage());
			standardData.setReturnCode(CodeMsg.CODE_EXCEPTION);
			standardData.setReturnMessage(CodeMsg.MSG_EXCEPTION);
			standardData.setReturnData(weixin);
		}
			standardData.setReturnData(weixin);
			standardData.setReturnCode(CodeMsg.CODE_OK);
			standardData.setReturnMessage(CodeMsg.MSG_OK);
		return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
	}
	
	//修改
	@ResponseBody
	@RequestMapping("modifyWeixin")
	public String modifyWeixin(HttpServletRequest request,HttpServletResponse response,Weixin weixin){
		ReturnStandardDataFormat standardData = new ReturnStandardDataFormat(CodeMsg.CODE_ERROR,CodeMsg.MSG_ERROR,null);
		//判断参数是否正确
		try {
			if(CommonUtils.isStrNull(weixin.getWeixinuser_Id())||CommonUtils.isStrNull(weixin.getWeixin_name())){
					standardData.setReturnCode(CodeMsg.CODE_ERROR_PARAMS);
					standardData.setReturnMessage(CodeMsg.MSG_ERROR_PARAMS);
					return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
			}else{
				//参数转码
				weixin.setWeixinuser_Id(EncodingUtils.fixUrlParamEncoding(request, weixin.getWeixinuser_Id()));
				weixin.setWeixin_name(EncodingUtils.fixUrlParamEncoding(request, weixin.getWeixin_name()));
			}
			//判断修改微信号id是否相同
			if(weixinService.queryById(weixin.getWeixin_id(),weixin.getWeixinuser_Id())){
				standardData.setReturnCode(CodeMsg.CODE_ERROR_OTHER);
				standardData.setReturnMessage("该微信号已存在，请重新输入");
				return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
			}
			Weixin yweixin=weixinService.queryWeixinById(weixin.getWeixin_id());
			//修改
			if(weixinService.modifyWeixin(weixin)){
				//操作记录
				ActiveUser opuser = getUser(request);//获取操作用户
				OptRecord s = new OptClass().weixin_updata(opuser,Menu.Resourceallocation.toString(),
						Menu.weixin.toString(),Operation.update.toString(),yweixin,weixin);
				ioptRecordService.insert(s);	
				standardData.setReturnCode(CodeMsg.CODE_OK);
				standardData.setReturnMessage(CodeMsg.MSG_OK);
			}else{
				standardData.setReturnCode(CodeMsg.CODE_ERROR);
				standardData.setReturnMessage(CodeMsg.MSG_ERROR);
			}
		} catch (Exception e) {
			log.error("修改微信号异常");
			ActiveUser opuser = getUser(request);//获取操作用户
			OptRecord s = new OptClass().recordabnormality(opuser,"微信号配置修改异常");
			ioptRecordService.insert(s);
			standardData.setReturnCode(CodeMsg.CODE_EXCEPTION);
			standardData.setReturnMessage(CodeMsg.MSG_EXCEPTION);
		}
		return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
	}
	//查询全部的接口
	@ResponseBody
	@RequestMapping("queryByIdName")
	public String queryByIdName(HttpServletRequest request,HttpServletResponse response,Integer pageIndex,Integer pageSize){
		List<Weixin> list = new ArrayList<Weixin>();
		ReturnStandardDataFormat standardData = new ReturnStandardDataFormat(CodeMsg.CODE_ERROR,CodeMsg.MSG_ERROR,list);
		PageView pageView = null;
		try {
			//给分页参数赋初始值
			if(pageIndex == null || pageIndex <= 0){
				pageIndex = 1;
			}
			if(pageSize == null || pageSize <= 0){
				pageSize = 10;
			}
			pageView = new PageView(pageSize,pageIndex);
			list = weixinService.queryByIdName(pageView);
		} catch (Exception e) {
			log.error("查询异常");
			log.error(e.getMessage());
			standardData.setReturnCode(CodeMsg.CODE_EXCEPTION);
			standardData.setReturnMessage(CodeMsg.MSG_EXCEPTION);
			standardData.setReturnData(list);
		}
		standardData.setReturnData(list);
		standardData.setReturnCode(CodeMsg.CODE_OK);
		standardData.setReturnMessage(CodeMsg.MSG_OK);
		standardData.setTotalPages(pageView.getPageCount());
		standardData.setTotalRecords(pageView.getRowCount());
		return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
	}
	//导出模板
	@ResponseBody
	@RequestMapping("exportExcelForModel")
	public String exportExcelForModel(HttpServletRequest request,HttpServletResponse response){
		
		ReturnStandardDataFormat standardData = new ReturnStandardDataFormat(CodeMsg.CODE_ERROR,CodeMsg.MSG_ERROR,null);
		List<Weixin> list = new ArrayList<Weixin>();
		try {
			List<String> titles = Arrays.asList("微信id","微信名");
			List<String> paramsName = Arrays.asList("weixinuser_Id",
					"weixin_name");
			OutputStream out = null;
			try {
				//获取输出流
				out = response.getOutputStream();
				//清空流
				response.reset();
				//定义响应输出类型
				response.setContentType("application/msexcel");
				//定义输出文件头
				response.setHeader("Content-disposition", 
						"attachment; filename=" + new String("微信号置模版".getBytes("GBK"), "iso8859-1") + ".xls");
				ExcelUtils.exportExcel(titles, paramsName, list, out);
			} catch (Exception e) {
				log.error(e.getMessage());
			}finally{
				//关闭流
				out.close();
			}
				ActiveUser opuser = getUser(request);//获取操作用户
				OptRecord s = new OptClass().modelxz(opuser,Menu.Resourceallocation.toString(),
						Menu.weixin.toString(),Operation.modelxz.toString(),"导入模板下载");
				ioptRecordService.insert(s);	
		} catch (Exception e) {
			log.error(e.getMessage());
		}
		return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
	}
	//导出数据
	@ResponseBody
	@RequestMapping("exportExcelForPageData")
	public String exportExcelForPageData(HttpServletRequest request,HttpServletResponse response,String weixin_id){
		ReturnStandardDataFormat standardData = new ReturnStandardDataFormat(CodeMsg.CODE_ERROR,CodeMsg.MSG_ERROR,null);
		try {
			//定义表头
			List<String> titls = Arrays.asList("编号","标签值","微信id","微信名","微信状态");
			//定义表字段名
			List<String> paramsName = Arrays.asList("weixin_id","tagvalue_id","weixinuser_Id",
					"weixin_name","is_deletes");
			//集合id
			List<Integer> idlist = new ArrayList<Integer>();
			List<Weixin> weixin = null;
			//判断
			if(StringUtils.isNoneBlank(weixin_id)){
				//分割id
				for (String strids : weixin_id.split(",")) {
					idlist.add(Integer.valueOf(strids));
				}
				weixin = weixinService.queryWeixinbyid(idlist);
			}
			//定义一个输出流
			OutputStream out = null;
			try {
				//获取流
				out = response.getOutputStream();
				//清空流
				response.reset();
				//响应输出类型
				response.setContentType("application/msexcel");
				//设置文件输出头
				response.setHeader("Content-disposition", 
						"attachment; filename=" + new String("微信信息".getBytes("GBK"), "iso8859-1") + ".xls");
				//调用方法
				ExcelUtils.exportExcel(titls, paramsName, weixin, out);
			} catch (Exception e) {
				log.error(e.getMessage());
			}finally{
				//关闭流
				out.close();
			}
			//操作日志
			ActiveUser opuser = getUser(request);//获取操作用户
			OptRecord s = new OptClass().goiss(opuser,Menu.Resourceallocation.toString(),
					Menu.weixin.toString(),Operation.daochu.toString(),idlist.size());
			ioptRecordService.insert(s);	
		} catch (Exception e) {
			log.error(e.getMessage());
		}
		return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");			
	}
	
	//新方案根据类型查询微信业务ID
    @ResponseBody
    @RequestMapping("queryWeixinByType")
    public String queryWeixinByType(HttpServletRequest request,HttpServletResponse response,Integer pageIndex,Integer pageSize,
            String weixinuser_Id,String weixin_name,String ifm_id,String types){
        List<Weixin> list = new ArrayList<>();
        ReturnStandardDataFormat StandardData = new ReturnStandardDataFormat(CodeMsg.CODE_ERROR,CodeMsg.MSG_ERROR,list);
        PageView pageView = null;
        try {
        	List<String> k_1=new ArrayList<String>();
        	String[] s_1=new String[500];
        	if(!ifm_id.equals(null)&&ifm_id!="")
        	{
        	int s=Integer.parseInt(ifm_id);
        	Iformation  k = iformationService.selectbyifmid(s);
        	if(types.equals("p_wechatType"))
			{
        	 s_1=k.getIfm_getWechatId().split(",");
			}
			else
			{
			s_1 = k.getIfm_notWechatId().split(",");	
			}
        	if(s_1.length>0)
        	{
        	for(int i=0;i<s_1.length;i++)k_1.add(s_1[i]);
        	//修改微信显示优先级
            if(weixinService.modifyDisplay(1,k_1)){}
        	}
        	}
            //给分页参数赋初始值
            if(pageIndex == null || pageIndex <= 0){
                pageIndex = 1;
            }
            if(pageSize == null || pageSize <= 0){
                pageSize = 10;
            }
            pageView = new PageView(pageSize,pageIndex);
            //字符转换
            if(weixinuser_Id != null || "".equals(weixinuser_Id)){
                weixinuser_Id = EncodingUtils.fixUrlParamEncoding(request, weixinuser_Id);
            }
            if(weixin_name != null || "".equals(weixin_name)){
                weixin_name = EncodingUtils.fixUrlParamEncoding(request, weixin_name);
            }
            list = weixinService.queryWeixinIdByType(pageView,weixin_name, weixinuser_Id);
          //修改微信显示优先级
        	if(!ifm_id.equals(null)&&s_1.length>0&&ifm_id!="")
        	{
            if(weixinService.modifyDisplay(0,k_1)){};
        	}
        } catch (Exception e) {
            log.error("根据参数查询异常");
            log.error(e.getMessage());
            StandardData.setReturnCode(CodeMsg.CODE_EXCEPTION);
            StandardData.setReturnMessage(CodeMsg.MSG_EXCEPTION);
            StandardData.setReturnData(list);
        }
            StandardData.setReturnData(list);
            StandardData.setReturnCode(CodeMsg.CODE_OK);
            StandardData.setReturnMessage(CodeMsg.MSG_OK);
            StandardData.setTotalPages(pageView.getPageCount());
            StandardData.setTotalRecords(pageView.getRowCount());
            return JsonUtils.toString(StandardData, "yyyy-MM-dd HH:mm:ss");
    }
	//导入
	@ResponseBody
	@RequestMapping("importExcelModel")
	public String importExcelModel(HttpServletRequest request,HttpServletResponse response){
		ReturnStandardDataFormat standardData = new ReturnStandardDataFormat(CodeMsg.CODE_ERROR,CodeMsg.MSG_ERROR,null);
		String realPath = request.getSession().getServletContext().getRealPath("/uploadTemp/");
		File saveFile = null;
		//如果目录不存在就创建
		if(!new File("realPath").exists()){
			new File("realPath").mkdir();
		}
		saveFile = new File(new File(realPath),getUser(request).getUserAccount() + System.currentTimeMillis()+"weixin_temp.xls");
		//把request转型
		DefaultMultipartHttpServletRequest multipart = (DefaultMultipartHttpServletRequest)request;
		//获得文件
		MultipartFile multipartFile = multipart.getFile("importExcel");
		//保存解析出来的信息
		AnalyzeResult<Weixin> analyzeResult = new AnalyzeResult<Weixin>(true,"",new ArrayList<Weixin>());
		//接收导入失败的数据，成功此list的size为0，否则里面的数据为错误数据
		List<Integer> errorIndexList = new ArrayList<Integer>();
		try {
			//转换成file
			multipartFile.transferTo(saveFile);
			//进行数据检测，将数据写入analyzeResult.list中
			weixinService.analyzeExcelData(saveFile,analyzeResult);
			if(analyzeResult.isSuccess()){
				List<Weixin> list = analyzeResult.getList();
				//判断微信号是否相同
				for (Weixin weixin : list) {
					if(weixinService.queryById(null, weixin.getWeixinuser_Id())){
						standardData.setReturnCode(CodeMsg.CODE_ERROR_SAME);
						standardData.setReturnMessage("Excel中微信id有重复值");
						return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
					}
				}
				//通过判断重复值，执行新增
				for (Weixin weixin : list) {
					weixinService.addWeixin(weixin);
				}
				if(errorIndexList.size()==0){
					//新增一条操作记录
					//操作日志
					ActiveUser opuser = getUser(request);//获取操作用户
					OptRecord s = new OptClass().goiss(opuser,Menu.Resourceallocation.toString(),
							Menu.weixin.toString(),Operation.daoru.toString(),list.size());
					ioptRecordService.insert(s);	
					//导入数据成功
					standardData.setReturnCode(CodeMsg.CODE_OK);
					standardData.setReturnMessage(CodeMsg.MSG_OK);
				}else{
					ActiveUser opuser = getUser(request);//获取操作用户
					OptRecord s = new OptClass().goiss(opuser,Menu.Resourceallocation.toString(),
							Menu.weixin.toString(),Operation.daoru.toString(),list.size()-errorIndexList.size());
					ioptRecordService.insert(s);	
					//导入错误，返回相应行数
					standardData.setReturnCode(CodeMsg.CODE_ERROR_PARAMS);
					standardData.setReturnMessage("导入数据完成，存在部分数据导入失败："+errorIndexList.size());
				}
			}else{
				//检测数据失败，返回相应提示信息
				standardData.setReturnCode(CodeMsg.CODE_ERROR_SAME);
				standardData.setReturnMessage("检测数据格式错误："+analyzeResult.getErrorMessage());
			}
		} catch (Exception e) {
			log.error("导入微信异常");
			ActiveUser opuser = getUser(request);//获取操作用户
			OptRecord s = new OptClass().recordabnormality(opuser,"微信号配置导入异常");
			ioptRecordService.insert(s);
			standardData.setReturnCode(CodeMsg.CODE_ERROR);
			standardData.setReturnMessage(CodeMsg.MSG_ERROR);
		}finally{
			//结束后删除本地文件
			saveFile.delete();
		}
		return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
	}
}
